package main

import (
	"context"
	"fmt"
	"os/signal"
	"syscall"
	"time"
)

func main() {
	fmt.Println("Press Ctrl+C to exit")
	ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
	go func() {
		<-ctx.Done()
		fmt.Println("Received signal, Exiting...")
	}()

	ticker := time.NewTicker(1 * time.Second)
Loop:
	for {
		select {
		case <-ticker.C:
			fmt.Printf("[%s] hello, world!\n", time.Now().Format(time.RFC3339))
		case <-ctx.Done():
			ticker.Stop()
			fmt.Println("Received signal, ticker.Stop ")
			break Loop
		}
	}

	fmt.Println("Exit")
}
